//
//  TIMStorageManager.h
//  Demo_TIM
//
//  Created by Deli Xia on 2018/5/30.
//  Copyright © 2018年 Deli Xia. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>

@class TIMStorageModel;
@class TIMGroupFileInfo;
@class TIMUserInfo;
@class TIMFriendInfo;
@class TIMGroupInfo;
@class TIMMessage;
@class TIMEmojiContent;
@class TIMConversationInfo;
@interface TIMStorageManager : NSObject

// 上传图片返回的信息
@property (nonatomic, strong, readonly) NSString *uploadToken;
@property (nonatomic, strong, readonly) NSString *uploadUrl;
@property (nonatomic, strong, readonly) NSString *uploadKey;

// 评论组内返回的groupID, key是 下发的资源ID， value 是对应的groupID
@property (nonatomic, strong, readonly) NSDictionary *commentGroupDic;

// 创建群组返回的群组ID, key 是 “createGroup”， value是对应的ID 
@property (nonatomic, strong, readonly) NSDictionary *createGroupIdDic;

/**
 *  创建单例
 */
+ (TIMStorageManager *)sharedStorageManager;

/**
 *  销毁单例
 */
- (void)destory;

#pragma mark - User

/**
 *  获取所有用户信息
 */
- (NSArray *)getAllUserInfo;

/**
 *  获取用户信息
 */

- (TIMUserInfo *)getUserByUserID:(NSString *)userID;

/**
 *  获取当前用户信息
 */
- (TIMUserInfo *)getCurrentUserInfo;

#pragma mark - Friend

/**
 *  获取所有好友信息
 */
- (NSArray *)getAllFriendInfo;

/**
 *  从好友列表内获取好友信息
 */
- (TIMUserInfo *)getFriendByFriendID:(NSString *)friendID;

/**
 *  获取所有新好友信息
 */
- (NSArray *)getAllNewFriend;

/**
 *  删除新好友记录
 */
- (BOOL)deleteNewFriendRecord:(NSString *)newFriendId;

/**
 *  获取新好友未读数量
 */

- (NSInteger)getNewFriendUnreadTotalCount;

/**
 *  获取好友信息或者非好友信息
 */
- (TIMUserInfo *)getLocalContactByFriendID:(NSString *)friendID;

#pragma mark - Group

/**
 *  获取所有群组信息
 */
- (NSArray *)getAllGroupInfo;

/**
 *  获取群组内单个群成员信息
 */
- (TIMUserInfo *)getSingleMemberInfoByGroupID:(NSString *)groupID friendID:(NSString *)friendID;

/**
 *  获取群组内单个群组信息
 */
- (TIMGroupInfo *)getGroupInfoByGroupID:(NSString *)groupID;

/**
 *  获取群组内管理员信息
 *  @parm admin, 1代表admin, 0代表组员
 */
- (NSArray *)getGroupAdminByGroupID:(NSString *)group admins:(NSInteger)admin;

/**
 *  获取群组内5个群成员信息
 */
- (NSArray *)groupFiveMembersForGid:(NSString *)groupId andOwner:(NSString *)groupOwner;

/**
 *  获取群组邀请信息
 */
- (TIMGroupInfo *)getInviteUserGroupInfoByGroupId:(NSString *)groupId messageKey:(NSString *)messageKey;

#pragma mark - Conversation

/**
 *  获取所有会话列表
 */
- (NSArray *)getAllConversationsInfo;

/**
 *  删除某一条会话记录
 */
- (BOOL)deleteConversationWithSessionId:(NSString *)sessionId;

/**
 *  获取某一个会话列表
 */
- (TIMConversationInfo *)getSingleConversionByPartnerID:(NSString *)partnerId;

/**
 *  更新会话的最后一条conntent， isShow代表要不要一直显示。
 */
- (BOOL)updateConversionContentByGroupId:(NSString *)groupId content:(NSString *)content isShow:(BOOL)isShow;

/**
 *  获取所有未读消息
 */
- (NSInteger)getAllUnreadMessageCount;

/**
 *  单条未读消息数
 */
- (NSInteger)getUnreadMessageByfid:(NSString *)partnerId;

/**
 *  猎取邀请待确认数
 */
- (NSArray *)getInviteForWaitMessageByGroupId:(NSString *)groupId;

/**
 *  获取历史消息
 *  NSDictionary: @{@"message":data,@"isMore":@(hasMore)}
 */
- (NSDictionary *)getMessageRecordForPartnerID:(NSString *)partnerID date:(NSDate *)currentDate count:(NSInteger)count;

/**
 *  获取@消息
 */
- (NSArray *)getChatAateMsgByUserID:(NSString *)userID partnerID:(NSString *)partnerID aateState:(NSString *)aateState;


#pragma mark - Message
/**
 *  根据msgKey找到这一条消息 （用于撤回消息）
 */
- (TIMMessage *)selectMessageByMessageKey:(NSInteger)messageKey;

/**
 *  获取与某个好友/讨论组的聊天图片及视频
 */
- (NSArray *)chatImagesAndVideosBypartnerID:(NSString *)partnerID;

/**
 *  更新@消息状态
 */
- (BOOL)updataAateMsgStateBypartnerID:(NSString *)partnerID msgKey:(NSInteger)msgKey aateState:(NSString *)aateState;

#pragma mark - GroupFile
/**
 *  查找组内所的文件
 */
- (NSArray *)getGroupFileByGroupId:(NSString *)groupId;

/**
 *  查找组内单一文件
 */
- (TIMGroupFileInfo *)getGroupFileInfoByGroupId:(NSString *)groupId fileId:(NSString *)fileId;

#pragma mark --- 数据库写操作
/**
 *  更新群头像, 上层调用方合成头像后调用此方法
 */
- (BOOL)updateGroupAvatarPath:(NSString *)userAvatarUrl groupID:(NSString *)groupID;

/**
 *  修改单个群成员在你的所有群内备注 (包括陌生人)，包括好友备注，非好友备注
 */
- (BOOL)updateSingleGroupMemberAllRemark:(NSString *)friendId remark:(NSString *)remark;

/**
 *  清除新好友消息已读
 */
- (void)clearUnreadFromNewFriend;

/**
 *  清除会话消息为已读
 */
- (void)readConversionByPartnerId:(NSString *)partnerId;

/**
 *  清除待邀请消息为已读
 */
//- (BOOL)readConversionInviteMessageByPartnerId:(NSString *)partnerId;

/**
 * 保存图片消息图片和大小缓存
 */
- (BOOL)saveImageMessage:(TIMMessage *)message imageCachePath:(NSString *)imagePath imageSize:(CGSize)size;

/**
 * 保存语音消息本地缓存和时长
 */
- (BOOL)saveVoiceMessage:(TIMMessage *)message voiceCachePath:(NSString *)imagePath voiceTime:(CGFloat)time;

/**
 * 保存表情加载包消息本地缓存
 */
- (BOOL)saveEmojiMessage:(TIMMessage *)message emoji:(TIMEmojiContent *)emoji;


@end
